package com.iecas.enums;


import cn.hutool.core.exceptions.ExceptionUtil;
import com.iecas.handler.*;
import com.iecas.request.*;
import com.iecas.response.*;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum BizEnum {
    // 请求
    DISTRIBUTE_REQ(9999, new DistributeReqHandler(), DistributeReq.class),
    LOGIN_REQ(10000, new LoginReqHandler(), LoginReq.class),
    HEART_BEAT_REQ(10001, new HeartBeatReqHandler(), HeartBeatReq.class),
    JOIN_REQ(10002, new JoinReqHandler(), JoinReq.class),
    MOVE_REQ(10003, new MoveReqHandler(), MoveReq.class),
    FIRE_REQ(10004, new FireReqHandler(), FireReq.class),
    DEAD_REQ(10005, new DeadReqHandler(), DeadReq.class),


    // 响应
    DISTRIBUTE_RESP(19999, new DistributeRespHandler(), DistributeResp.class),
    LOGIN_RESP(20000, new LoginRespHandler(), LoginResp.class),
    HEART_BEAT_RESP(20001, new HeartBeatRespHandler(), HeartBeatResp.class),
    JOIN_BEAT_RESP(20002, new JoinRespHandler(), JoinResp.class),
    MOVE_RESP(20003, new MoveRespHandler(), MoveResp.class),
    FIRE_RESP(20004, new FireRespHandler(), FireResp.class),
    DEAD_RESP(20005, new DeadRespHandler(), DeadResp.class),
    ;
    int code;
    BaseHandler handler;
    Class<? extends Root> clazz;


    public static BizEnum getByCode(int code) {
        for (BizEnum value : BizEnum.values()) {
            if (value.getCode() == code) {
                return value;
            }
        }
        throw ExceptionUtil.wrapRuntime("未知请求:" + code);
    }
}
